package edu.olin.scheduler.common;

/**
 * A Meeting represents a single, continuous segment of time within a single day
 * during which a Course meets.  Meetings are immutable.
 */
public class Meeting {
    
    private Course owner; //the Course to which this Meeting belongs
    private int dayOfWeek; //the day of the week on which this Meeting occurs (0=Sunday)
    private SimpleTime start; //the SimpleTime when this meeting starts
    private SimpleTime end; //the SimpleTime when this meeting ends
    
    /**
     * Setter method.
     * The owner is the Course to which this Meeting belongs.
     * @return Nothing
     */
    public void setOwner(Course owner){
        if(owner==null){ throw new IllegalArgumentException("owner cannot be null"); }
        this.owner = owner;
    }
    
    /**
     * Accessor method.
     * The owner is the Course to which this Meeting belongs.
     * @return this Meeting's owner
     */
    public Course owner(){ return owner; }
    
    /**
     * Accessor method.
     * Gives the day of the week on which this Meeting occurs.
     * dayOfWeek is 0-based, where 0 represents Sunday
     * @return The day of the week on which this Meeting occurs
     */
    public int dayOfWeek(){ return dayOfWeek; }
    
    /**
     * Accessor method.
     * @return The SimpleTime at which this Meeting starts.
     * start must come before end (start.compareTo(end)<0)
     */
    public SimpleTime start(){ return start; }
    
    /**
     * Accessor method.
     * @return The SimpleTime at which this Meeting starts.
     * end must come after start (end.compareTo(start)>0)
     */
    public SimpleTime end(){ return end; }
    
    /**
     * Constructs a new Meeting with the given parameters
     * @param owner The Course to which this Meeting belongs
     * @param dayOfWeek The day of the week on which this Meeting occurs.
     * dayOfWeek is 0-based, where 0 represents Sunday
     * @param start The SimpleTime at which this Meeting starts
     * @param end The SimpleTime at which this Meeting ends
     */
    public Meeting(int dayOfWeek, SimpleTime start, SimpleTime end){
        if(start==null){ throw new IllegalArgumentException("start cannot be null"); }
        if(end==null){ throw new IllegalArgumentException("end cannot be null"); }
        if(start.compareTo(end)>=0){ throw new IllegalArgumentException("start must come before end"); }
        if(dayOfWeek<0 || dayOfWeek>6){ throw new IllegalArgumentException("Invalid day of week; 0<=day<=6"); }
        this.owner = owner;
        this.start = start;
        this.end = end;
        this.dayOfWeek = dayOfWeek;
    }
    
    /**
     * Accessor method.
     * @return The duration of this meeting in minutes
     */
    public int duration(){
        return end.minutesSinceMidnight() - start.minutesSinceMidnight();
    }
    
    
}
